{include file="public/header" /}

<body>
<div class="layui-card">
    <div class="layui-card-body">
        <form id="picFormData" class="layui-form layui-form-pane" autocomplete="off">
            <input type="hidden" name="id" value="{$info.id}">
            <div class="layui-tab layui-tab-card">
                <ul class="layui-tab-title">
                    <li class="layui-this">基本内容</li>
                    <li>SEO内容</li>
                </ul>

                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form-item">
                            <label class="layui-form-label layui-required">分类</label>
                            <div class="layui-input-block">
                                <select name="type" id="companyPicType">
                                    <option value="">请选择分类</option>
                                    {volist name='type' id='vo'}
                                    <option value="{$vo.id}" {if $info.type == $vo.id} selected {/if}>{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" id="name" value="{$info.name}" class="layui-input" placeholder="请输入">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-upload">
                                <label class="layui-form-label layui-required">图片</label>
                                <div class="layui-upload">
                                    <div class="layui-input-block">
                                        <div class="upload-frame {notempty name='info.img'}upload-btn-hide{/notempty}" id="uploadImg">
                                            <i class="layui-icon layui-icon-addition"></i>
                                        </div>
                                        <div class="preview-box">
                                            <div class="uploader-list" id="imgPreview">
                                                {notempty name="info.img"}
                                                <div class="file-items">
                                                    <div class="handle" data-flag="img" data-path="{$info.img}"><i class="layui-icon layui-icon-delete"></i></div>
                                                    <img src="{$info.img}">
                                                </div>
                                                {/notempty}
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                            <input type="hidden" name="img" id="imgUrl" value="{$info.img}">
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-block">
                                <input type="text" name="sort" id="sort" value="{$info.sort}" class="layui-input" placeholder="请输入排序，数字越小，排序越靠前">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block">
                                <input type="checkbox" name="status" id="status" {if $info.status == 1}checked {/if} lay-text="显示|隐藏" lay-skin="switch">
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-form-item">
                            <label class="layui-form-label">SEO关键词</label>
                            <div class="layui-input-block">
                                <input type="text" name="seo_keywords" id="bannerSeoKeywords" value="{$info.seo_keywords}" class="layui-input" placeholder="每个关键词用英文逗号隔开">
                            </div>
                        </div>

                        <!--<div class="layui-form-item">
                            <label class="layui-form-label">SEO描述</label>
                            <div class="layui-input-block">
                                <textarea name="seo_describe" id="pictureSeoDescribe" placeholder="请输入" class="layui-textarea">{$info.seo_describe}</textarea>
                            </div>
                        </div>-->
                    </div>

                    <div class="btn-block">
                        <button type="button" onclick="picSendFormData()" class="layui-btn layui-btn-normal"><i class="fa fa-check"></i>提交</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    layui.use(['form', 'element', 'upload'], function () {
        var $ = layui.jquery,
            form = layui.form,
            element = layui.element,
            upload = layui.upload;

        uploadTemplate('#uploadImg','#imgPreview','#imgUrl','img','imgLoad')

        function uploadTemplate(btn,preview,value,flag,load){
            upload.render({
                elem: btn,
                url: "{:url('company/upload')}",
                multiple: false,
                accept: 'file',
                size: uploadFileSize,
                acceptMime: uploadImgExt,
                before: function (obj) {
                    $(btn).addClass('upload-btn-hide')
                    $(preview).empty()
                    load = layer.load(1, {shade: [0.5, '#FFF'], time: 0})//弹出遮罩层
                },
                done: function (res) {
                    layer.close(load)//关闭遮罩层
                    sucMsg(res.msg)
                    if (res.code == 'suc') {
                        $(preview).append(
                            '<div class="file-items">' +
                            '<div class="handle" data-flag="' + flag +'" data-path="' + res.url + '"><i class="layui-icon layui-icon-delete"></i></div>' +
                            '<img class="cover-preview" src="' + res.url + '">' +
                            '</div>'
                        );

                        $(value).val(res.url)
                    } else {
                        $(btn).removeClass('upload-btn-hide')
                    }
                }
            })
        }
    })

    //删除图片
    $(document).on("click", ".file-items .handle", function (event) {
        let flag = $(this).attr('data-flag')
        $('#uploadImg').removeClass('upload-btn-hide')
        $("#imgUrl").val('')
        $(this).parent().remove();
    })

    function picSendFormData() {
        let type = $('#companyPicType').val()
        let imgUrl = $("#imgUrl").val();
        if (emptyCheck(type)) {
            hintMsg('请选择分类', 'companyPicType')
            return false
        } else if (emptyCheck(imgUrl)) {
            hintMsg('请上传图片')
            return false
        }
        let data = $("#picFormData").serialize()
        //弹出遮罩层，防止多次点击
        var companyPicLoad = layer.load(1, {shade: [0.5, '#FFF'], time: 0})
        ajaxRequest("{:url('company/editPicture')}", data, function (res) {
            if (res.code == 'suc') {
                sucMsg(res.msg, function () {
                    //刷新父级页面
                    parent.layui.table.reload('companyPictureList')
                    //关闭遮罩层
                    layer.close(companyPicLoad)
                    //关闭当前弹出层
                    xadmin.close()
                })
            } else {
                errMsg(res.msg, function () {
                    //关闭遮罩层
                    layer.close(companyPicLoad)
                })
            }
        })
    }
</script>
</html>